package com.example.jdk8.threads;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

public class ThreadScheduledExecutor {
    public static void main(String[] args) throws InterruptedException {
        // 初始化线程池
        ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1);
        // 创建线程实例
        Runnable task = () -> {
            System.out.println();
            System.out.println("Scheduling: "+ System.nanoTime());
        };
        // 把实例线程装进线程池
        ScheduledFuture<?> future = executorService.schedule(task, 3, TimeUnit.SECONDS);
        // 设置延迟时间
        TimeUnit.MILLISECONDS.sleep(1337);
        long delay = future.getDelay(TimeUnit.MILLISECONDS);
        System.out.printf("Remaining Delay %s ms  ", delay);
    }
}
